<?php
function fw24h_db_connect( $_FW24H_CONFIG_) {
	$FW24H_ACTIVE_DB = mysqli_connect( $_FW24H_CONFIG_['server'], $_FW24H_CONFIG_['username'], $_FW24H_CONFIG_['password'], $_FW24H_CONFIG_['database'], $_FW24H_CONFIG_['port']) or trigger_error( mysqli_error( $FW24H_ACTIVE_DB), E_USER_ERROR);
	//mysqli_select_db( $FW24H_ACTIVE_DB, $_FW24H_CONFIG_['database']) or trigger_error( mysqli_error( $FW24H_ACTIVE_DB), E_USER_ERROR);
	return $FW24H_ACTIVE_DB;
}

function fw24h_db_query( $sql, $connection) {
	// log sql command
	if( DEBUG_MODE) {
		$f_error_msg = date( 'Y-m-d H:i:s')."; SQL: $sql\n";
		error_log( $f_error_msg, 3, APP_DIR.'/logs/sql.log');
	}
	$rs = mysqli_query( $connection, $sql) or trigger_error( mysqli_error( $connection).';;;'.$sql, E_USER_ERROR);
	return $rs;
}

function fw24h_db_insert_id( $connection) {
	return mysqli_insert_id( $connection);
}

function fw24h_db_fetch_assoc( $result) {
	return mysqli_fetch_assoc( $result);
}

function fw24h_db_free_result( $result) {
	return mysqli_free_result( $result); 
}

function fw24h_db_fetch_array( $result, $connection) {
	return mysqli_fetch_array( $result);
}

function fw24h_db_affected_rows( $connection) {
	return mysqli_affected_rows( $connection);
}

function fw24h_db_close( $connection) {
	return mysqli_close( $connection);
}

function fw24h_db_data_seek( $result, $number) {
	return mysqli_data_seek( $result, $number);
} 

function fw24h_db_errno( $connection) {
	return mysqli_errno( $connection);
}

function fw24h_db_error( $connection) {
	return mysqli_error( $connection);
}


